#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include "mytest.h"
#include "form.h"
#include <QMessageBox>
#include <QFile>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);


    pt = new myTest;
    connect(pt,SIGNAL(qqq(int)), this, SLOT(ttt(int)));

    QPixmap pixmap;
    if(false == pixmap.load("d:/2.bmp"))
    {
        qDebug()<<"图片加载失败"<<endl;
    }

    ui->label_2->setPixmap(pixmap);
    ui->label_2->setScaledContents(true);

    connect(ui->label_2,SIGNAL(clicked()),this,SLOT(linkActivated()));

//    setStyleSheet("QLineEdit[echoMode='2']{background:red};QPushbutton{backgroud}");

    // 加载QSS文件
    QFile file(":/test.qss"); // 假设style.qss位于资源文件中
    if (file.open(QFile::ReadOnly)) {
        QString stylesheet = QString(file.readAll());//读取文件中的所有内容返回给QString的构造函数
        setStyleSheet(stylesheet); // 应用全局样式
        file.close();
    }

    setWindowFlag(Qt::FramelessWindowHint,true);//去掉主窗口的边框
    setAttribute(Qt::WA_TranslucentBackground,true);//把主窗口透明
}

void MainWindow::linkActivated()
{
    close();
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    if(ui->username->text()=="zhangsan"&&ui->password->text()=="123456")
    {
        Form * pForm = new Form;
        pForm->show();
        hide();
        if(ui->save->isChecked()==true)
        {
            qDebug()<<"用户想保存密码"<<endl;
        }
        if(ui->auto_2->isChecked()==true)
        {
            qDebug()<<"用户想下次自动登录"<<endl;
        }
    }
    else
    {
        QMessageBox::about(this,"登录失败","账号或者密码错误");
    }
}

void MainWindow::ttt(int x)
{
    qDebug()<<"收到qqq信号，参数为："<<x<<endl;
}

void MainWindow::anNiuCaoHanShu(bool checked)
{
    qDebug()<<"自定义槽函数!"<<checked<<endl;
    pt->qqq(100);//发射信号，信号参数为100
}
